<?php
namespace Index\Controller;
use Think\Controller;

class FeedbackController extends Controller {

	public function feedback(){

        $feed = M('message');
		
		if(I('post.')){
			$data = I('post.');
			empty('name') && $this->error('Please Insert your name!',1);
			empty('email') && $this->error('Please Insert your email!',1);
			$res = $feed->add($data);
			if($res){
				$this->success('We have got your message and will reply you ASAP ^^. Thank you.',U('feedback'),1);
			}else{
				$this->error('Maybe network got a little busy, hold.... or you can just contact us via Contact Page',U('feedback'),1);
			}
		}

		//get category
		$cate = M('category');
		$getTopCate = $cate->where(['pid'=>0])->order('sort asc')->select();

		foreach($getTopCate as &$v){
			$v['sub'] = $cate->where(['pid'=>$v['id']])->select();
		}

		//web config
		$getInfo = M('web_config');
		$getConf = $getInfo->find(1);
		$getConf['logo_img'] = '/Public/Uploads/'.$getConf['logo_img'];
		
		$n = M('news');
		$news = $n->select();

		$this->assign([
			'getConf'=>$getConf,
			'news'  => $news,
			'getCate'=>$getTopCate,
		
		]);

        $this->display();
        }
	





}
